package com.pureut.production.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.security.utils.SecurityUtils;
import com.pureut.production.domain.AmHrGuardrecord;
import com.pureut.production.domain.AmHrSkillrequest;
import com.pureut.production.domain.AmHrSkills;
import com.pureut.production.domain.vo.AmHrGuardrecordVo;
import com.pureut.production.domain.vo.AmHrSkillrequestRespVo;
import com.pureut.production.domain.vo.AmHrSkillrequestVo;
import com.pureut.production.service.AmHrGuardrecordService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/guardrecord")
public class AmHrGuardrecordController extends BaseController {
    @Resource
    private AmHrGuardrecordService amHrGuardrecordService;

    @GetMapping("/list")
    public TableDataInfo list(AmHrGuardrecordVo amHrGuardrecordVo) {
        startPage();
        AmHrGuardrecord amHrGuardrecord = new AmHrGuardrecord();
        amHrGuardrecord.setGuardCode(amHrGuardrecordVo.getGuardCode());
        amHrGuardrecord.setEmpno(amHrGuardrecordVo.getEmpno());
        amHrGuardrecord.setEmpname(amHrGuardrecordVo.getEmpname());
        List<AmHrGuardrecord> list = amHrGuardrecordService.list(new QueryWrapper<>(amHrGuardrecord).orderByDesc("create_time"));
        TableDataInfo dataTable = getDataTable(list);
        return dataTable;
    }

    @PostMapping("/add")
    public AjaxResult add(@RequestBody AmHrGuardrecord amHrGuardrecord) {
        amHrGuardrecord.setCreateTime(new Date());

        return toAjax(amHrGuardrecordService.save(amHrGuardrecord));
    }

    @DeleteMapping("/delete/{id}")
    public AjaxResult remove(@PathVariable("id") Long id) {
        return toAjax(amHrGuardrecordService.removeById(id));
    }

    @GetMapping("/view/{id}")
    public AjaxResult view(@PathVariable("id") Long id) {
        return AjaxResult.success(amHrGuardrecordService.getById(id));
    }

    @PostMapping("/update")
    public AjaxResult update(@RequestBody AmHrGuardrecord amHrGuardrecord) {
        return toAjax(amHrGuardrecordService.updateById(amHrGuardrecord));
    }

}
